/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VentanaListaCarnes.java
 *
 * Created on 09-oct-2011, 18:55:41
 */
package kusterordonio.interfaz;

import java.awt.event.KeyEvent;
import java.util.*;
import javax.swing.JOptionPane;
import kusterordonio.dominio.*;

/**
 *
 * @author Usuario
 */
public class VentanaListaCarnes extends javax.swing.JFrame {
    
    private SistemaCarne modelo;
    private Persona persona;
    private boolean caso;
    
    /** Creates new form VentanaListaCarnes */
    public VentanaListaCarnes() {
        initComponents();
        jBtnVerCarne.setMnemonic(KeyEvent.VK_V);
        jBtnSalir.setMnemonic(KeyEvent.VK_S);
    }
    
    public VentanaListaCarnes(SistemaCarne unSistema, boolean unCaso, Persona unaPersona) {
        modelo = unSistema;
        persona= unaPersona;
        caso = unCaso;
        
        initComponents();
        jTxtCedula.setText(persona.toString());
        if(caso)
            //Médico: todos los niños
            this.jListCarnes.setListData(modelo.getListaNinios().toArray());
        else
            //Padre, madre o tutor: sus hijos
            cargarLista(persona.getCedulaId());
   }


    public void cargarLista(String cedula){
        ArrayList<Ninio> listaHijos = modelo.listaHijos(cedula);
        if(!listaHijos.isEmpty())
            this.jListCarnes.setListData(listaHijos.toArray());
        else
            jBtnVerCarne.setEnabled(false);
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jListCarnes = new javax.swing.JList();
        jLabel1 = new javax.swing.JLabel();
        jTxtCedula = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabelNinio = new javax.swing.JLabel();
        jLabelNinia = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jBtnVerCarne = new javax.swing.JButton();
        jBtnSalir = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Lista de Carnés");
        setBounds(new java.awt.Rectangle(200, 100, 400, 400));
        setMinimumSize(new java.awt.Dimension(600, 500));
        setResizable(false);

        jPanel1.setLayout(null);

        jListCarnes.setFont(new java.awt.Font("Tahoma", 1, 11));
        jScrollPane1.setViewportView(jListCarnes);

        jPanel1.add(jScrollPane1);
        jScrollPane1.setBounds(190, 140, 220, 280);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel1.setForeground(new java.awt.Color(0, 102, 204));
        jLabel1.setText("Lista de Carnés");
        jPanel1.add(jLabel1);
        jLabel1.setBounds(20, 20, 160, 22);

        jTxtCedula.setBackground(new java.awt.Color(255, 255, 255));
        jTxtCedula.setEditable(false);
        jTxtCedula.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jPanel1.add(jTxtCedula);
        jTxtCedula.setBounds(260, 90, 150, 20);

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("Usuario:");
        jPanel1.add(jLabel2);
        jLabel2.setBounds(190, 90, 80, 20);
        jPanel1.add(jSeparator1);
        jSeparator1.setBounds(0, 50, 600, 10);

        jLabelNinio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kusterordonio/recursos/NinioPeque.gif"))); // NOI18N
        jPanel1.add(jLabelNinio);
        jLabelNinio.setBounds(20, 150, 130, 160);

        jLabelNinia.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kusterordonio/recursos/NiniaPeque.gif"))); // NOI18N
        jPanel1.add(jLabelNinia);
        jLabelNinia.setBounds(290, 200, 300, 160);

        jPanel2.setBackground(new java.awt.Color(0, 102, 204));
        jPanel2.setLayout(null);

        jBtnVerCarne.setText("Ver Carné");
        jBtnVerCarne.setBorder(null);
        jBtnVerCarne.setBorderPainted(false);
        jBtnVerCarne.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnVerCarneActionPerformed(evt);
            }
        });
        jPanel2.add(jBtnVerCarne);
        jBtnVerCarne.setBounds(60, 370, 80, 22);

        jBtnSalir.setText("Salir");
        jBtnSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnSalirActionPerformed(evt);
            }
        });
        jPanel2.add(jBtnSalir);
        jBtnSalir.setBounds(180, 370, 80, 22);

        jPanel1.add(jPanel2);
        jPanel2.setBounds(140, 70, 320, 420);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 600, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 502, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBtnSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnSalirActionPerformed
        this.dispose();
    }//GEN-LAST:event_jBtnSalirActionPerformed

    private void jBtnVerCarneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnVerCarneActionPerformed
       if(!jListCarnes.isSelectionEmpty()){
            Ninio niño = (Ninio)jListCarnes.getSelectedValue();
            boolean genero = niño.isSexo();
            VentanaCarne vent = new VentanaCarne(modelo, niño, genero, persona, caso);
            vent.setVisible(true);
       }
       else
           JOptionPane.showMessageDialog(null,"Debe elegir un carné", "Error", 2);
           
        
    }//GEN-LAST:event_jBtnVerCarneActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBtnSalir;
    private javax.swing.JButton jBtnVerCarne;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabelNinia;
    private javax.swing.JLabel jLabelNinio;
    private javax.swing.JList jListCarnes;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextField jTxtCedula;
    // End of variables declaration//GEN-END:variables
}
